package cn.taobaoke.restful.util;

import java.util.Random;
import java.util.stream.IntStream;

public class RandomUtil {

    private static final String tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    /**
     * 根据指定的字符产生指定位数的随机码
     * @return
     */
    public static String generateInviteCode(int bit) {
        Random random = new Random();
        IntStream intStream = random.ints(0, tokens.length());
        StringBuilder builder = new StringBuilder();
        intStream.limit(bit).forEach(it -> builder.append(tokens.charAt(it)));
        return builder.toString();
    }
}
